package com.ruoyi.xp.supply.service.impl;

import com.ruoyi.xp.supply.domain.SupplyWarehouseGoods;
import com.ruoyi.xp.supply.dto.SupplyWarehouseGoodsDto;
import com.ruoyi.xp.supply.mapstruct.GoodsMap;
import com.ruoyi.xp.supply.service.ISupplyWarehouseGoodsService;
import com.ruoyi.xp.supply.service.ISupplyWarehouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author chendx
 */
@Service
public class SupplyWarehouseServiceImpl implements ISupplyWarehouseService {

    @Autowired
    private ISupplyWarehouseGoodsService supplyWarehouseGoodsService;

    @Resource
    private GoodsMap goodsMap;

    @Override
    public void updateOrAddWarehouseGoods(List<SupplyWarehouseGoodsDto> supplyWarehouseGoodsDtoList) {
        for (SupplyWarehouseGoodsDto supplyWarehouseGoodsDto : supplyWarehouseGoodsDtoList) {
            SupplyWarehouseGoods supplyWarehouseGoods = goodsMap.mapSupplyWarehouseGoodsDtoToEntity(supplyWarehouseGoodsDto);
            int result = supplyWarehouseGoodsService.updateSupplyWarehouseGoods(supplyWarehouseGoods);
            if (result == 0) {
                supplyWarehouseGoodsService.insertSupplyWarehouseGoods(supplyWarehouseGoods);
            }
        }
    }
}
